package org.vectrics.recruiter.struts.tag;

import org.vectrics.company.*;
import org.vectrics.location.*;
import org.vectrics.struts.VectricsTagSupport;
import org.apache.log4j.Category;
import org.vectrics.common.html.*;
import org.apache.ecs.html.A;
import java.text.SimpleDateFormat;

/**
 * @author Mike Moore
 * @version 1.0
 */

abstract public class CompanySummaryTag extends VectricsTagSupport {

	private static final long serialVersionUID = -6140221889206853891L;
	
	private static Category log = Category.getInstance(CompanySummaryTag.class);
    private String entryTypeParam = "";
    private SimpleDateFormat jobDateFormat = new SimpleDateFormat("MM-yyyy");
    private static int SECTION_WIDTH = 400;
    
    
    protected String getEditCompanyHref() {
        return("/hrs-public/main/user/edit");        
    }
    
    protected Table getCompanyInfoTable(Company company) {
        Table mainTable = new Table();
        mainTable.setWidth(400);
        Row mainRow = mainTable.addRow();
        Cell mainCell = mainRow.addCell();
        
        
        Table table = new Table();
        table.setWidth(400);
        mainCell.addElement(table);
        
        Row row = table.addRow();
        Cell cell = row.addCell();
        cell.addElement(TextHelper.getFont("stdFont", "<b>Company Name</b>"));
        cell = row.addCell();
        cell.addElement(TextHelper.getFont("stdFont", company.getName()));
        
        row = table.addRow();
        cell = row.addCell();
        cell.setWidth(150);
        cell.addElement(TextHelper.getFont("stdFont", "<b>" + this.getPhrase("prompt.company.reference.id") +  "</b>"));
        cell = row.addCell();
        cell.addElement(TextHelper.getFont("stdFont", company.getReferenceId()));

        
        row = table.addRow();
        cell = row.addCell();
        cell.setWidth(150);
        cell.addElement(TextHelper.getFont("stdFont", "<b>" + this.getPhrase("prompt.company.sector") +  "</b>"));
        cell = row.addCell();
        cell.addElement(TextHelper.getFont("stdFont", this.getPhrase(company.getSector().getDescriptionCode())));
        
        
        mainCell.addElement("<br><br>"); 


        A link = new A();
        link.setHref(getEditCompanyHref());
        link.setClass("subLink");
        link.addElement("Change");
        mainCell.addElement(link);

        return(mainTable);
    }   
   /* 
    protected String doRender(Request request, Properties params) {
        log.debug("doRender() called");
        String companyParam = request.getParameter("company");

        Table mainTable = new Table();
        Row mainRow = mainTable.addRow();
        Cell mainCell = mainRow.addCell();

        if (companyParam != null) {
            Company company = null;
            try {
                company = CompanyUtil.getLocalHome().findByPrimaryKey(new CompanyPK(companyParam));
            }
            catch (Exception ex) {
                log.error("doRender() - exception finding company ejb.", ex);
            }
            
            mainCell.addElement(getCompanyInfoTable(company));
        }

        return(mainTable.toString());
    }
    */
    
    protected Row makeFieldRow(Table table, String caption, String value) {
        log.debug("makeFieldRow() - creating display field in row of html table");
        if ((value == null) || (value.trim().equals(""))) {
            value = "<i>Not Given</i>";
        }
        Row row = table.addRow();
        Cell cell = row.addCell();
        cell.setVAlign("top");
        cell.addElement(TextHelper.getFont("stdFont", "<b>" + caption + "</b>"));
        cell = row.addCell();
        cell.addElement("&nbsp;");
        cell = row.addCell();
        cell.addElement(TextHelper.getFont("stdFont", value));
        return(row);
    }
    
    
   private String getAddressHtml(Address address) {
       log.debug("getAddressHtml() called");
       String str = "<i>No Address Entered</i>";
       if (address != null) {
           if ((address.getAddress1() != null) && (address.getAddress1().length() > 0))
               str = TextHelper.escapeHtml(address.getAddress1()) + "<br>";
           if ((address.getAddress2() != null) && (address.getAddress2().length() > 0))
               str += TextHelper.escapeHtml(address.getAddress2()) + "<br>";
           if ((address.getCity() != null) && (address.getCity().length() > 0))
               str += TextHelper.escapeHtml(address.getCity()) + ", ";
           if ((address.getState() != null) && (address.getState().length() > 0))
               str += TextHelper.escapeHtml(address.getState()) + ", ";
           if ((address.getPostalCode() != null) && (address.getPostalCode().length() > 0))
               str += TextHelper.escapeHtml(address.getState()) + "&nbsp;&nbsp;";
           if (str.length() > 0) {
               str += "<br>";
           }
           if ((address.getCountryCode() != null) && (address.getCountryCode().length() > 0))
               str += TextHelper.escapeHtml(address.getCountryCode()) + "&nbsp;&nbsp;";

           if (str.length() <= 0) {
               str = "<i>No Address Entered</i>";
           }
       }
       return(str);
   }

   
    
}